﻿using System;
using System.Collections.Generic;
using System.Text;
using Microsoft.Win32;

public class Licensing
{
    DateTime GetServerDate()
    {
        //try
        //{
        //    string tarih = new DbSqlServer( Factory.GetFactory.ExecuteScaler("SELECT CAST(YEAR(GETDATE()) AS VARCHAR) + '-' +CAST(MONTH(GETDATE()) AS VARCHAR) + '-' +CAST(DAY(GETDATE()) AS VARCHAR)").ToString();
        //    string[] dizi = tarih.Split('-');
        //    if (dizi.Length > 0)
        //        return new DateTime(int.Parse(dizi[0]), int.Parse(dizi[1]), int.Parse(dizi[2]));
        //    else
        //        return DateTime.Now;
        //}
        //catch (Exception)
        //{
        //    return DateTime.Now;
        //}
        return DateTime.Now;
    }

    public bool CheckEvaluate()
    {
        try
        {
            if (Registry.ClassesRoot.OpenSubKey("Microsoft.Workflow").OpenSubKey("CLSID").GetValueNames().Length > 0)
                if (Registry.ClassesRoot.OpenSubKey("Microsoft.Workflow").OpenSubKey("CLSID").GetValue("").ToString() == "{C512165B-37F1-45b4-826D-346F894B0144}")
                    return false;

            DateTime currentDate = GetServerDate();
            if (currentDate >= new DateTime(2012, 6, 1))
            {
                Registry.ClassesRoot.CreateSubKey("Microsoft.Workflow").CreateSubKey("CLSID").SetValue("", "{C512165B-37F1-45b4-826D-346F894B0144}");
                return false;
            }
            else
            {
                Registry.ClassesRoot.CreateSubKey("Microsoft.Workflow").CreateSubKey("CLSID").SetValue("", "");
                return true;
            }
        }
        catch (Exception)
        {
            return false;
        }
    }
}

